package app.test;

import org.ricks.common.conf.NetWorkConfig;
import org.ricks.ioc.*;

public class AppMain {

	public static void main(String[] args) throws Exception {
//		FileWatcher watcher = new FileWatcher("",new DataListener()); //初始化data文件变化监听
		NetWorkConfig.setPort(9999); //如果配置服务器端口，可以不写
//		LogConfig.setLevel("debug"); //设置日志等级
		AppContext.setBannerMode(Banner.Mode.OFF); //设置banner 是否开启，默认开启
		AppContext.run(AppMain.class);//启动容器 & 启动server
//		DispatchManager.init(ApplicationContext.getApplication());
//		byte[] data = DispatchManager.getData();
//		ClassLoad classLoad = new ClassLoad();
//		classLoad.defineClass1("Dispatcher",data,0,data.length);
//		watcher.watch();//开始监听

//		DispatchManager.init(ApplicationContext.getApplication());

//		Thread.sleep(5000L);
//		Dispatcher.dispatcher(new Context<Short,Byte[]>(null,new Message((short)1,new byte[0])));

//		Dispatcher dispatcher = new Dispatcher();
//
		org.ricks.common.Context context = new org.ricks.common.Context(null,new Message((short)1000,new byte[0]));
//
//		dispatcher.dispatcher(context);
//		Class clazz = Class.forName("org.demon.dispatch.Dispatcher");
//		Object o = clazz.getConstructor().newInstance();
//		Method mm = clazz.getMethod("dispatcher",Context.class);
//
//		try {
//			mm.invoke(o,context);
//		} catch (Exception e) {
//			System.err.println("+++++++++" + Thread.currentThread().getStackTrace().length);
//			throw e;
//		}
////		for (Method m: ms) {
////			System.err.println(m.getName());
////			if(m.getName().equals("dispatcher")) {
////				m.invoke(o,context);
////			}
////		}
//		System.err.println("...............");

//		ClassReader classReader = new ClassReader("org.demon.dispatch.Dispatcher");
//		ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
//		ClassVisitor cv = new DispatchClassVisitor(classWriter);
//		classReader.accept(cv,0);
//		DispatchManager.ClassLoad myClassLoader = new DispatchManager.ClassLoad();
//		Class classByBytes = myClassLoader.defineClassToJvm("org.demon.dispatch.Dispatcher",classWriter.toByteArray());
//		String dispatch_path = FileUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath() + "org/demon/dispatch/Dispatcher.class";
//		System.err.println(dispatch_path);
//		byte[] data =  classWriter.toByteArray();
//		FileOutputStream fos = new FileOutputStream(dispatch_path);
//		fos.write(data);
//		Object o = classByBytes.newInstance();
//		Method method = classByBytes.getMethod("dispatcher", Context.class);
//		method.invoke(o,context);
//		System.out.println("Method method :  " );

	}

}
